<template>
	<view>
		<view class="uni-list">
			<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(value,key) in res" :key="key" @click="jump" :data-goodsid="value.goodsid">
				<view class="uni-media-list">
					<view class="uni-media-list-logo">
						<image :src="value.thumb"></image>
					</view>
					<view class="uni-media-list-body">
						<view class="uni-media-list-text-top ellipsis-1" v-cloak>{{value.title}}</view>
						<view class="uni-media-list-text-bottom uni-ellipsis">
							<text style="color: #f55;margin-right: 6upx;" v-cloak>¥{{value.marketprice}}</text>
							<text style="text-decoration: line-through;" v-cloak>¥{{value.productprice}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more v-if="load == 1" :loadingType="loadingType" :contentText="contentText"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from '../../components/uni-load-more.vue'
	export default {
		data() {
			return {
				res:[],
				index:2,
				loadingType:0,
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多了"
				},
				systemInfo: {},
				load: 0,
				openid:''
			};
		},
		onLoad:function(){
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../login/login'
					});
				}
			});
			uni.getSystemInfo({
				success: (res) => {
					this.systemInfo = res
				}
			})
		},
		onReachBottom(){
			if (this.loadingType !== 0) {
				return;
			}
			this.loadingType = 1;
			uni.request({
				url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.favorite.get_list&app=1&page='+this.index,
				method: 'POST',
				data: {'openid':this.openid},
				header:{'Content-Type':'application/x-www-form-urlencoded'},
				success: res => {
					if(res.data.result.list.length == 0){
						this.loadingType = 2;
						return;
					}
					this.res = this.res.concat(res.data.result.list)
					this.loadingType = 0;
					this.index = this.index + 1;
				},
				fail: () => {},
				complete: () => {}
			});
			
		},
		components: {uniLoadMore},
		methods:{
			setAjax(){
				uni.request({
					url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.favorite.get_list&app=1&page=1',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						this.res = res.data.result.list;
						if(res.data.result.total > res.data.result.pagesize){
							this.load = 1
						}
						uni.hideLoading();
					},
					fail: () => {},
					complete: () => {}
				});
			},
			jump(e){
				var goodsid = e.currentTarget.dataset.goodsid
				uni.navigateTo({
					url: '../goods/detail?goodsid='+goodsid
				});
			}
		},
		onReachBottom(){
		}
	}
</script>

